package com.oamicnet.servicetwo.server.controller;

import com.oamicnet.servicetwo.server.entity.Course;
import com.oamicnet.servicetwo.server.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/school/course")
@RefreshScope
public class CourseController {

    @Autowired
    public CourseService courseService;

    @GetMapping("/{id}")
    public Course getCourseById(@PathVariable("id") Long id) {
        return courseService.get(id);
    }

    @GetMapping
    public List<Course> getCourses() {
        return courseService.findAll();
    }

    @PostMapping
    public void saveCourse(@RequestBody Course course) {
        courseService.save(course);
    }

    @PutMapping
    public void updateCourse(@RequestBody Course course) {
        courseService.update(course);
    }

    @DeleteMapping("/{id}")
    public void deleteCourse(@PathVariable("id") Long id) {
        courseService.delete(id);
    }
}
